import axios from 'axios'

const request = axios.create({
    baseURL: 'https://api.realworld.io'
})

request.interceptors.request.use(config => {
    let token = localStorage.getItem('jwt')
    if (token) {
      config.headers['Authorization'] = `Token ${token}`
    }
    return config
  },
  error => {
    return Promise.reject(error)
  })

request.interceptors.response.use(response => {
    // 对响应数据做点什么
    return response.data;
}, error => {
    // 对响应错误做点什么
    return Promise.reject(error);
})

export default request